import type { UserDto, UserPageDto } from '../../../dto/acl/user'
import { Sex } from '../../../dto/acl/user'

function getUserInfo(): UserDto[] {
  return [
    {
      id: 1,
      imageUrl:
        'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Ff316c639-7a42-43cf-93e6-77ce4f14071c%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=9027e7bb8698bfb39b240ad28d6ff92b',
      userName: 'admin',
      sex: Sex.男,
      account: 'admin',
      role: '角色1',
      createDate: '2024-3-25 10:55:12',
      updateDate: null,
    },
    {
      id: 2,
      imageUrl:
        'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fcfebc1cd-d48a-413d-9451-2c0546cf6d53%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=a72d18cbaf87e5099cb89541d7d50900',
      userName: '吕权华',
      sex: Sex.男,
      account: 'lqh',
      role: '管理员',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 3,
      imageUrl:
        'https://img0.baidu.com/it/u=558103304,2805165250&fm=253&fmt=auto&app=120&f=JPEG?w=667&h=500',
      userName: '陆雪琪',
      sex: Sex.女,
      account: 'lxq',
      role: '角色2',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 4,
      imageUrl:
        'https://img0.baidu.com/it/u=3024894384,3886349382&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=800',
      userName: '小李子',
      sex: Sex.男,
      account: 'xlz',
      role: '角色2',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 5,
      imageUrl:
        'https://puui.qpic.cn/vpic_cover/s3521ofhqj1/s3521ofhqj1_1688274624_hz.jpg/1280',
      userName: '孟川',
      sex: Sex.男,
      account: 'mc',
      role: '角色2',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 6,
      imageUrl:
        'https://i2.hdslb.com/bfs/archive/fd18bee66116e436a0f5846e13d63b3af8382d79.jpg',
      userName: '梅元知',
      sex: Sex.男,
      account: 'xy',
      role: '角色2',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 7,
      imageUrl:
        'https://t11.baidu.com/it/u=2923942608,213795777&fm=30&app=106&f=JPEG?w=640&h=376&s=BA9305C500090B5D5298E02D0300F041',
      userName: '杨过',
      sex: Sex.男,
      account: 'yg',
      role: '角色3',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
    {
      id: 8,
      imageUrl:
        'https://img1.baidu.com/it/u=3565987574,3075812149&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
      userName: '小龙女',
      sex: Sex.女,
      account: 'xln',
      role: '角色3',
      createDate: '2024-3-26 10:55:12',
      updateDate: null,
    },
  ]
}

function getUsers(): UserPageDto[] {
  return [
    {
      sizePage: 5,
      count: 8,
      curPage: 1,
      users: [
        {
          id: 1,
          imageUrl:
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Ff316c639-7a42-43cf-93e6-77ce4f14071c%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=9027e7bb8698bfb39b240ad28d6ff92b',
          userName: 'admin',
          sex: Sex.男,
          account: 'admin',
          role: '角色1',
          createDate: '2024-3-25 10:55:12',
          updateDate: null,
        },
        {
          id: 2,
          imageUrl:
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fcfebc1cd-d48a-413d-9451-2c0546cf6d53%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=a72d18cbaf87e5099cb89541d7d50900',
          userName: '吕权华',
          sex: Sex.男,
          account: 'lqh',
          role: '管理员',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 3,
          imageUrl:
            'https://img0.baidu.com/it/u=558103304,2805165250&fm=253&fmt=auto&app=120&f=JPEG?w=667&h=500',
          userName: '陆雪琪',
          sex: Sex.女,
          account: 'lxq',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 4,
          imageUrl:
            'https://img0.baidu.com/it/u=3024894384,3886349382&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=800',
          userName: '小李子',
          sex: Sex.男,
          account: 'xlz',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 5,
          imageUrl:
            'https://puui.qpic.cn/vpic_cover/s3521ofhqj1/s3521ofhqj1_1688274624_hz.jpg/1280',
          userName: '孟川',
          sex: Sex.男,
          account: 'mc',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
      ],
    },
    {
      sizePage: 5,
      count: 8,
      curPage: 2,
      users: [
        {
          id: 6,
          imageUrl:
            'https://i2.hdslb.com/bfs/archive/fd18bee66116e436a0f5846e13d63b3af8382d79.jpg',
          userName: '梅元知',
          sex: Sex.男,
          account: 'xy',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 7,
          imageUrl:
            'https://t11.baidu.com/it/u=2923942608,213795777&fm=30&app=106&f=JPEG?w=640&h=376&s=BA9305C500090B5D5298E02D0300F041',
          userName: '杨过',
          sex: Sex.男,
          account: 'yg',
          role: '角色3',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 8,
          imageUrl:
            'https://img1.baidu.com/it/u=3565987574,3075812149&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
          userName: '小龙女',
          sex: Sex.女,
          account: 'xln',
          role: '角色3',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
      ],
    },
    {
      sizePage: 10,
      count: 8,
      curPage: 1,
      users: [
        {
          id: 1,
          imageUrl:
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Ff316c639-7a42-43cf-93e6-77ce4f14071c%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=9027e7bb8698bfb39b240ad28d6ff92b',
          userName: 'admin',
          sex: Sex.男,
          account: 'admin',
          role: '角色1',
          createDate: '2024-3-25 10:55:12',
          updateDate: null,
        },
        {
          id: 2,
          imageUrl:
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fcfebc1cd-d48a-413d-9451-2c0546cf6d53%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1717663007&t=a72d18cbaf87e5099cb89541d7d50900',
          userName: '吕权华',
          sex: Sex.男,
          account: 'lqh',
          role: '管理员',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 3,
          imageUrl:
            'https://img0.baidu.com/it/u=558103304,2805165250&fm=253&fmt=auto&app=120&f=JPEG?w=667&h=500',
          userName: '陆雪琪',
          sex: Sex.女,
          account: 'lxq',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 4,
          imageUrl:
            'https://img0.baidu.com/it/u=3024894384,3886349382&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=800',
          userName: '小李子',
          sex: Sex.男,
          account: 'xlz',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 5,
          imageUrl:
            'https://puui.qpic.cn/vpic_cover/s3521ofhqj1/s3521ofhqj1_1688274624_hz.jpg/1280',
          userName: '孟川',
          sex: Sex.男,
          account: 'mc',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 6,
          imageUrl:
            'https://i2.hdslb.com/bfs/archive/fd18bee66116e436a0f5846e13d63b3af8382d79.jpg',
          userName: '梅元知',
          sex: Sex.男,
          account: 'xy',
          role: '角色2',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 7,
          imageUrl:
            'https://t11.baidu.com/it/u=2923942608,213795777&fm=30&app=106&f=JPEG?w=640&h=376&s=BA9305C500090B5D5298E02D0300F041',
          userName: '杨过',
          sex: Sex.男,
          account: 'yg',
          role: '角色3',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
        {
          id: 8,
          imageUrl:
            'https://img1.baidu.com/it/u=3565987574,3075812149&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
          userName: '小龙女',
          sex: Sex.女,
          account: 'xln',
          role: '角色3',
          createDate: '2024-3-26 10:55:12',
          updateDate: null,
        },
      ],
    },
  ]
}

export default [
  // 查询用户接口
  {
    url: '/api/acl/user', //请求地址
    method: 'get', //请求方式
    response: (data) => {
      //获取请求体携带过来的用户名与密码
      const { userName, account } = data.query
      //调用获取用户信息函数,用于判断是否有此用户
      const checkUser: UserDto[] = getUserInfo().filter(
        (item) => item.userName === userName || item.account === account,
      )

      //没有用户返回失败信息
      if (checkUser.length === 0) {
        return {
          code: 201,
          message: '找不到数据',
          ok: false,
          data: null,
        }
      }
      //如果有返回成功信息
      return {
        code: 200,
        message: null,
        ok: true,
        data: checkUser,
      }
    },
  },

  // 获取所有用户
  {
    url: '/api/acl/users',
    method: 'get',
    response: (data) => {
      const { page, pageSize } = data.query
      const checkUser = getUsers().find(
        (item) => item.curPage == page && item.sizePage == pageSize,
      )

      //没有返回失败的信息
      if (!checkUser) {
        return { code: 201, message: '获取用户信息失败', ok: false, data: null }
      }
      //如果有返回成功信息
      return { code: 200, message: null, ok: true, data: checkUser }
    },
  },
]
